$("header").load("header.html");
$("footer").load("footer.html");

// 判断是否登录


let documentWidth = $(document).width();
let play1 = [];
$(".carousel").width(documentWidth);
for (let i = -1; i < $(".carousel-play").length; i++) {
    play1.push(documentWidth * i);
    play1.max = play1[i];
}
for (let i = 0; i < $(".carousel-play").length; i++) {
    $(".carousel-play").eq(i).css({ "left": play1[i] })
}
play1.min = play1[0];
$(".carousel-last").click(function() {
    console.log("上")
    for (let i = 0; i < play1.length; i++) {
        play1[i] -= documentWidth;
        if (play1[i] < play1.min) {
            play1[i] = play1.max;
            $(".carousel-play").eq(i).animate({ left: play1[i] }, 0);
        }

        $(".carousel-play").eq(i).animate({ left: play1[i] }, 500);
    }
});
$(".carousel-next").click(function() {
    console.log("下")
    for (let i = 0; i < play1.length; i++) {
        play1[i] += documentWidth;
        if (play1[i] > play1.max) {
            play1[i] = play1.min;
            $(".carousel-play").eq(i).animate({ left: play1[i] }, 0);
        }
        $(".carousel-play").eq(i).animate({ left: play1[i] }, 500)

    }
});



// 第二个轮播图
let play2 = [];
for (let i = -1; i < $(".carousel-slideshow-two>li").length - 1; i++) {
    play2.push(i * 350);
}
for (let i = 0; i < $(".carousel-slideshow-two>li").length; i++) {
    $(".carousel-slideshow-two>li").eq(i).css("left", play2[i]);
}
play2.min = play2[0];
play2.max = play2[play2.length - 1];
$(".carousel-two-last").click(function() {
    for (let i = 0; i < play2.length; i++) {
        play2[i] -= 350;
        if (play2[i] < play2.min) {
            play2[i] = (play2.length - 2) * 350;
            $(".carousel-slideshow-two>li").eq(i).animate({ left: play2[i] }, 0)
        }
        $(".carousel-slideshow-two>li").eq(i).animate({ left: play2[i] })
    }
});
$(".carousel-two-next").click(function() {
    for (let i = 0; i < play2.length; i++) {
        play2[i] += 350;
        if (play2[i] > play2.max) {
            play2[i] = play2.min;
            $(".carousel-slideshow-two>li").eq(i).animate({ left: play2[i] }, 0)
        }
        $(".carousel-slideshow-two>li").eq(i).animate({ left: play2[i] })
    }
});

// 第三个轮播图
let play3 = [];
for (let i = -1; i < $(".carousel-play-three").length - 1; i++) {
    play3.push(i * 1000);
}
for (let i = 0; i < $(".carousel-play-three").length; i++) {
    $(".carousel-play-three").eq(i).css("left", play3[i]);
}
play3.min = play3[0];
play3.max = play3[play3.length - 1];
// console.log(play3,play3.max,play3.min);
$(".carousel-three-last").click(function() {
    console.log("上");
    for (let i = 0; i < play3.length; i++) {
        play3[i] -= 1000;
        if (play3[i] < play3.min) {
            play3[i] = (play3.length - 3) * 1000;
            $(".carousel-play-three").eq(i).animate({ left: play3[i] }, 0)
        }
        $(".carousel-play-three").eq(i).animate({ left: play3[i] })
    }
});
$(".carousel-three-next").click(function() {
    console.log("下");
    for (let i = 0; i < play3.length; i++) {
        play3[i] += (+1000);
        if (play3[i] > play3.max) {
            play3[i] = play3.min;
            $(".carousel-play-three").eq(i).animate({ left: play3[i] }, 0)
        }
        $(".carousel-play-three").eq(i).animate({ left: play3[i] })
    }
});
// 第四个轮播图
let play4 = [];
for (let i = -1; i < $(".carousel-play-four").length - 1; i++) {
    play4.push(i * 335);
}
for (let i = 0; i < $(".carousel-play-four").length; i++) {
    $(".carousel-play-four").eq(i).css("left", play4[i]);
}
play4.min = play4[0];
play4.max = play4[play4.length - 1];
$(".carousel-four-last").click(function() {
    for (let i = 0; i < play4.length; i++) {
        play4[i] -= 335;
        if (play4[i] < play4.min) {
            play4[i] = (play4.length - 2) * 335;
            $(".carousel-play-four").eq(i).animate({ left: play4[i] }, 0)
        }
        $(".carousel-play-four").eq(i).animate({ left: play4[i] })
    }
});
$(".carousel-four-next").click(function() {
    for (let i = 0; i < play4.length; i++) {
        play4[i] += 335;
        if (play4[i] > play4.max) {
            play4[i] = play4.min;
            $(".carousel-play-four").eq(i).animate({ left: play4[i] }, 0)
        }
        $(".carousel-play-four").eq(i).animate({ left: play4[i] })
    }
});

// 潮品力推选品按钮
$(".tide-select-man-btn").click(function() {
    optionMan($(this));
})
$(".tide-select-woman-btn").click(function() {
    optionWoman($(this));
})

// 篮球选品按钮
$(".basketball-select-btn-one").click(function() {
    $(this).css("backgroundColor", "#78c9da");
    $(".basketball-select-btn-two").css("backgroundColor", "black")
    $(".basketball-select-btn-three").css("backgroundColor", "black")
    $(".basketball-select-one").css("display", "flex").animate({ opacity: 1 });
    $(".basketball-select-two").animate({ opacity: 0 }, function() {
        $(this).css("display", "none");
    })
    $(".basketball-select-three").animate({ opacity: 0 }, function() {
        $(this).css("display", "none");
    })
});
$(".basketball-select-btn-two").click(function() {
    $(this).css("backgroundColor", "#78c9da");
    $(".basketball-select-btn-one").css("backgroundColor", "black")
    $(".basketball-select-btn-three").css("backgroundColor", "black")
    $(".basketball-select-two").css("display", "flex").animate({ opacity: 1 });
    $(".basketball-select-one").animate({ opacity: 0 }, function() {
        $(this).css("display", "none");
    })
    $(".basketball-select-three").animate({ opacity: 0 }, function() {
        $(this).css("display", "none");
    })
});
$(".basketball-select-btn-three").click(function() {
    $(this).css("backgroundColor", "#78c9da");
    $(".basketball-select-btn-two").css("backgroundColor", "black")
    $(".basketball-select-btn-one").css("backgroundColor", "black")
    $(".basketball-select-three").css("display", "flex").animate({ opacity: 1 });
    $(".basketball-select-two").animate({ opacity: 0 }, function() {
        $(this).css("display", "none");
    })
    $(".basketball-select-one").animate({ opacity: 0 }, function() {
        $(this).css("display", "none");
    })
});

// 跑步系类按钮
$(".man-running-but").click(function() {
    optionMan($(this));
});
$(".woman-running-but").click(function() {
    optionWoman($(this));
})

// 运动生活选品按钮
$(".man-exercise-but").click(function() {
    optionMan($(this));
});
$(".woman-exercise-but").click(function() {
    optionWoman($(this));
})

// 训练系列选品按钮
$(".man-drill-but").click(function() {
    optionMan($(this));
});
$(".woman-drill-but").click(function() {
    optionWoman($(this));
})

// 刷街潮鞋系列选品按钮
$(".man-tideway-but").click(function() {
    optionMan($(this));
});
$(".woman-tideway-but").click(function() {
    optionWoman($(this));
})

// 精选服饰选品按钮
$(".man-costume-but").click(function() {
    optionMan($(this));
});
$(".woman-costume-but").click(function() {
    optionWoman($(this));
})

// 儿童选品按钮
$(".man-children-but").click(function() {
    optionMan($(this));
});
$(".woman-children-but").click(function() {
        optionWoman($(this));
    })
    // 包包选品按钮
$(".man-handbag-but").click(function() {
    optionMan($(this));
});
$(".woman-handbag-but").click(function() {
    optionWoman($(this));
})

function optionMan(btn) {
    btn.css("backgroundColor", "#78c9da");
    btn.next().css("backgroundColor", "black")
    btn.parent().next().children().eq(0).css("display", "flex").animate({ opacity: 1 });
    btn.parent().next().children().eq(1).animate({ opacity: 0 }, function() {
        $(this).css("display", "none");
    })
}

function optionWoman(btn) {
    btn.css("backgroundColor", "#78c9da");
    btn.prev().css("backgroundColor", "black")
    btn.parent().next().children().eq(1).css("display", "flex").animate({ opacity: 1 });
    btn.parent().next().children().eq(0).animate({ opacity: 0 }, function() {
        $(this).css("display", "none");
    });
}
for (let i = 0; i < $("a").length; i++) {
    if ($("a").eq(i).attr("href") == "#") {
        $("a").eq(i).attr("href", "commodityPage.html");
        // console.log($("a").eq(i));

        // console.log(document.querySelectorAll("a")[i]);
    }
}
$(document).ready(function() {
    let local = localStorage;
    for(let i = 0,s = 1;i<$(".link-detail-page a").length;i++,s++,i++){
        $(".link-detail-page a").eq(i).click(function(){
            $(this).attr("goods-id",s)
            local.id = $(this).attr("goods-id");
            $(location).attr('href', 'detailPage.html');
            return false;
        })
        $(".link-detail-page a").eq(i+1).click(function(){
            $(this).attr("goods-id",s)
            local.id = $(this).attr("goods-id");
            $(location).attr('href', 'detailPage.html');
            return false;
        })
    }
    // $(".link-detail-page a").click(function(){

    //     return false;
    // })
    
})